package com.gengzp.mq.common.enums;

import lombok.Getter;

/**
 * @ClassName MessageStatusEnum
 * @Description 消息状态枚举类
 * @Author gengzp
 * @Date 2025/6/8 13:29
 */
@Getter
public enum MessageStatusEnum {

    UNCONSUMED(0, "未消费"),
    CONSUMING(1, "消费中"),
    CONSUMED(2, "已消费"),
    CONSUMED_FAIL(3, "消费失败"),
    ;

    private final Integer code;
    private final String value;

    MessageStatusEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    /**
     * 根据编码获取枚举值
     */
    public static String getValueByCode(Integer code) {
        for (MessageStatusEnum messageStatusEnum : MessageStatusEnum.values()) {
            if (messageStatusEnum.getCode().equals(code)) {
                return messageStatusEnum.value;
            }
        }
        return null;
    }

    /**
     * 根据枚举值获取编码
     */
    public static Integer getValueByValue(String value) {
        for (MessageStatusEnum messageStatusEnum : MessageStatusEnum.values()) {
            if (messageStatusEnum.getValue().equals(value)) {
                return messageStatusEnum.code;
            }
        }
        return null;
    }

}
